package com.zzy.algorithm.tree;

import com.zzy.algorithm.model.TreeNode;

/**
 * LeetCode - 101 : 对称二叉树
 *
 * 给你一个二叉树的根节点 root ， 检查它是否轴对称。
 *
 * 解题思路：
 * 方法一：
 */
public class Q21_SymmetricBinaryTree {

    public static void main(String[] args) {
        Q21_SymmetricBinaryTree q21_symmetricBinaryTree = new Q21_SymmetricBinaryTree();
        boolean symmetric = q21_symmetricBinaryTree.isSymmetric(TreeNode.treeNode1.left,TreeNode.treeNode1.right);
        System.out.println("symmetric = " + symmetric);
    }

    private boolean isSymmetric(TreeNode left,TreeNode right){
        if(left == null && right == null){
            return true;
        }
        if(left == null || right == null){
            return false;
        }
        if(left.val != right.val){
            return false;
        }
        return isSymmetric(left.left,right.right) && isSymmetric(left.right,right.left);
    }


}
